define(['jquery', 'bootstrap', 'backend', 'table', 'form','bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form,showJumpto) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zbtask/import/index' + location.search,
                    add_url: 'zbtask/import/add',
                    edit_url: 'zbtask/import/edit',
                    del_url: 'zbtask/import/del',
                    multi_url: 'zbtask/import/multi',
                    table: 'zbtask_import',
                }
            });

            var table = $("#table");
            var toAjax = function (ids, index,url) {
                var options = table.bootstrapTable('getOptions');
                var search = options.queryParams({});
                Fast.api.ajax({
                    url: url,
                    data: {
                        ids: ids,
                        filter: search.filter,

                        searchFast: options.searchText
                    }
                }, function (ret) {
                    Layer.close(index);
                    $(".btn-refresh").trigger("click");
                });
            };
            $(document).on("click", ".btn-selected", function () {
                var ids = Table.api.selectedids(table);  //所有选中的项
                var page = table.bootstrapTable('getData');  //当前页面
                var all = table.bootstrapTable('getOptions').totalRows; //所有行
                var url = 'zbtask/import/sureSubmit';
                Layer.confirm("确认提交数据到正式众包费吗？",
                    {
                        title: '确认提交到正式数据吗？',
                        btn: ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
                        yes: function (index, layero) {
                            toAjax(ids, index,url);
                            return false;
                        },
                        btn2: function (index, layero) {
                            var ids = [];
                            $.each(page, function (i, j) {
                                ids.push(j.id);
                            });
                            toAjax(ids, index, url);
                            return false;
                        },
                        btn3: function (index, layero) {
                            toAjax('all', index, url);
                            return false;
                        }
                    });
            });
            $.fn.bootstrapTable.locales[Table.defaults.locale].formatSearch = function(){return "姓名/身份证";};
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showJumpto: true,
                searchFormVisible: true,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'zbtask.name', title: __('Zbtask.name'),operate:false},
                        {field: 'real_name', title: __('Real_name')},
                        {field: 'identity_card', title: __('Identity_card')},
                        {field: 'bank_card', title: __('Bank_card'),operate:false},
                        {field: 'task_id', title: __('Task_id'),visible:false, addClass: "selectpage", extend: "data-source='zbtask/zbtask/index'  data-field='name' data-order-by='id desc'"},
                        {field: 'mobile', title: '电话',operate:false},
                        {field: 'money', title: __('Money'),operate:false},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: '格式是否正确', searchList: {"0":'待验证',"1":'正确', "2":'错误'}, formatter: Table.api.formatter.status},
                        {field: 'money_type', title: __('Money_type'), searchList: {"1":__('Money_type 1'),"2":__('Money_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'is_import', title: __('Is_import'), searchList: {"0":__('Is_import 0'),"1":__('Is_import 1')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});